import ImgUpload from 'e-ui/lib/ImgUpload'
import tools from 'utils/tools'
import { Upload } from '@element-ui'
import api from 'api'

ImgUpload.components = {
  ...ImgUpload.components,
  Upload
}

ImgUpload.props.headers = {
  type: Object,
  default () {
    return tools.getHeaders()
  }
}

ImgUpload.methods.uploadCropImage = function (image) {
  var self = this
  self.loading = true
  api.uploadCropper({upfile: image}, {successMsg: '图片裁剪成功！'}).then(function (res) {
    self.loading = false
    self.handleSuccess(res)
  }).catch(function () {
    self.loading = false
  })
}

export default ImgUpload
